
from datetime import datetime
from object.database import db

class Logistics(db.Model):
    __tablename__ = 'logistics'
    LogisticsID = db.Column('LogisticsID', db.BIGINT, primary_key=True, autoincrement=False)
    VendorID = db.Column('VendorID', db.Integer, nullable=False)
    OrderID = db.Column('OrderID', db.BIGINT, nullable=False)
    Address = db.Column('Address', db.String(255),nullable=False)
    Consignee = db.Column('Consignee', db.String(255),nullable=False)
    Telephone = db.Column('Telephone', db.String(255),nullable=False)
    Status = db.Column('Status', db.String(20), nullable=False)
    Remarks = db.Column('Remarks', db.Text, nullable=True)

    def __repr__(self):
        return f"<Logistics {self.LogisticsID}>"



class Logisticstrack(db.Model):
    __tablename__ = 'logisticstrack'
    TrackID = db.Column('TrackID', db.Integer, primary_key=True, autoincrement=True)
    LogisticsID = db.Column('LogisticsID', db.Integer, nullable=False)
    Node=db.Column('Node',db.Text,nullable=False)

    def __repr__(self):
        return f"<Logisticstrack {self.TrackID}>"


class Logisticsvendors(db.Model):
    __tablename__ = 'logisticsvendors'
    VendorID = db.Column('VendorID', db.Integer, primary_key=True, autoincrement=True)  # 主键
    VendorName = db.Column('VendorName', db.String(100), nullable=False)  # 不允许为 NULL
    ContactNumber = db.Column('ContactNumber', db.String(20), nullable=True)  # 允许为 NULL
    Address = db.Column('Address', db.String(255), nullable=True)  # 允许为 NULL
    Country = db.Column('Country', db.String(100), nullable=True)  # 允许为 NULL
    Remarks = db.Column('Remarks', db.Text, nullable=True)  # 允许为 NULL

    def __repr__(self):
        return f"<Logisticsvendors {self.VendorID}>"



class Orders(db.Model):
    __tablename__ = 'orders'
    OrderID = db.Column('OrderID', db.BIGINT, primary_key=True)  # 主键
    Status = db.Column('Status', db.String(20), nullable=False)  # 状态字段，非空
    CreatedAt = db.Column('CreatedAt', db.DateTime,default=datetime.now, nullable=False)  # 创建时间，非空
    UpdatedAt = db.Column('UpdatedAt', db.DateTime,onupdate=datetime.now, default=datetime.now, nullable=True)  # 更新时间，可空
    SKU=db.Column('SKU',db.String(100),nullable=False)
    Amount = db.Column('Amount', db.Integer, nullable=False)  # 数量字段
    Remarks = db.Column('Remarks', db.Text, nullable=True)  # 备注，可空

    def __repr__(self):
        return f"<Orders {self.OrderID}>"



class Permissions(db.Model):
    __tablename__ = 'permissions'
    PermissionID = db.Column('PermissionID', db.Integer, primary_key=True, autoincrement=True)  # 主键
    Role = db.Column('Role', db.String(50), nullable=False)  # 角色名称，非空
    AccessLevel = db.Column('AccessLevel', db.String(50), nullable=False)  # 权限级别，非空
    Remarks = db.Column('Remarks', db.Text, nullable=True)  # 备注，可空

    def __repr__(self):
        return f"<Permissions {self.PermissionID}>"


class Reports(db.Model):
    __tablename__ = 'reports'
    ReportID = db.Column('ReportID', db.Integer, primary_key=True, autoincrement=True)  # 主键
    Type = db.Column('Type', db.String(50), nullable=False)  # 报告类型，非空
    Content = db.Column('Content', db.Text, nullable=False)  # 报告内容，非空
    Remarks = db.Column('Remarks', db.Text, nullable=True)  # 备注，可空

    def __repr__(self):
        return f"<Reports {self.ReportID}>"



class User(db.Model):
    __tablename__ = 'user'
    UserID = db.Column('UserID', db.Integer, primary_key=True, autoincrement=True)  # 主键，自增
    UserName = db.Column('UserName', db.String(100), nullable=False)  # 用户名，非空
    Password = db.Column('Password', db.String(255), nullable=False)  # 密码，非空
    PermissionID = db.Column('PermissionID', db.Integer, db.ForeignKey('permissions.PermissionID'), nullable=True)  # 外键，可空

    def __repr__(self):
        return f"<User {self.UserID}, {self.UserName}>"



class Warehousing(db.Model):
    __tablename__ = 'warehousing'
    WarehouseID = db.Column('WarehouseID', db.Integer, primary_key=True, autoincrement=True)  # 主键，自增
    SKU=db.Column('SKU',db.String(100),nullable=False)
    TransactionType = db.Column('TransactionType', db.String(20), nullable=False)  # 交易类型，非空
    OrderID = db.Column('OrderID', db.BIGINT, db.ForeignKey('orders.OrderID'), nullable=False)  # 外键，非空
    Description = db.Column('Description', db.Text, nullable=True)  # 描述，可空
    Timestamp = db.Column('Timestamp', db.DateTime, nullable=False,default=datetime.now)  # 时间戳，非空

    def __repr__(self):
        return f"<Warehousing {self.WarehouseID}>"



class Product(db.Model):
    __tablename__ = 'product'
    ProductID = db.Column('ProductID', db.Integer, primary_key=True, autoincrement=True)
    Name = db.Column('Name', db.String(255), nullable=False)
    Description = db.Column('Description', db.Text, nullable=True)
    Price = db.Column('Price', db.Numeric(10, 2), nullable=False)
    Currency = db.Column('Currency', db.String(10), nullable=False)
    Country = db.Column('Country', db.String(100), nullable=False)
    Status = db.Column('Status', db.String(255), nullable=False)
    Remarks = db.Column('Remarks', db.Text, nullable=True)
    Cover = db.Column('Cover', db.String(255), nullable=False)

    def __repr__(self):
        return f"<Product {self.ProductID}>"

class ProductSpecification(db.Model):
    __tablename__ = 'productspecification'
    ProductID = db.Column('ProductID', db.Integer, primary_key=True, nullable=False)
    SpecID = db.Column('SpecID', db.Integer, primary_key=True, nullable=False)

    def __repr__(self):
        return f"<ProductSpecification ProductID={self.ProductID}, SpecID={self.SpecID}>"

class ProductVariant(db.Model):
    __tablename__ = 'productvariant'
    VariantID = db.Column('VariantID', db.Integer, primary_key=True, autoincrement=True)
    ProductID = db.Column('ProductID', db.Integer, db.ForeignKey('product.ProductID'), nullable=False)
    SKU = db.Column('SKU', db.String(100), unique=True, nullable=False)
    Price = db.Column('Price', db.Numeric(10, 2), nullable=False)
    Stock = db.Column('Stock', db.Integer, nullable=False)

    def __repr__(self):
        return f"<ProductVariant {self.VariantID}>"

class Specification(db.Model):
    __tablename__ = 'specification'
    SpecID = db.Column('SpecID', db.Integer, primary_key=True, autoincrement=True)
    SpecName = db.Column('SpecName', db.String(100), nullable=False)
    Remarks = db.Column('Remarks', db.Text, nullable=True)

    def __repr__(self):
        return f"<Specification {self.SpecID}>"

class SubSpecification(db.Model):
    __tablename__ = 'subspecification'
    SubSpecID = db.Column('SubSpecID', db.Integer, primary_key=True, autoincrement=True)
    SpecID = db.Column('SpecID', db.Integer, db.ForeignKey('specification.SpecID'), nullable=False)
    SubSpecName = db.Column('SubSpecName', db.String(100), nullable=False)
    Remarks = db.Column('Remarks', db.Text, nullable=True)

    def __repr__(self):
        return f"<SubSpecification {self.SubSpecID}>"

class VariantSpecification(db.Model):
    __tablename__ = 'variantspecification'
    VariantID = db.Column('VariantID', db.Integer, primary_key=True, nullable=False)
    SubSpecID = db.Column('SubSpecID', db.Integer, primary_key=True, nullable=False)

    def __repr__(self):
        return f"<VariantSpecification VariantID={self.VariantID}, SubSpecID={self.SubSpecID}>"